package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.enums.DelFlag;
import com.ruoyi.system.domain.DangKou;
import com.ruoyi.system.mapper.DangkouMapper;
import com.ruoyi.system.service.IDangkouService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 食堂档口信息表 服务实现类
 * </p>
 *
 * @author qubaofeng
 * @since 2025-02-06
 */
@Service
public class DangkouServiceImpl extends ServiceImpl<DangkouMapper, DangKou> implements IDangkouService {

    @Override
    public List<DangKou> selectDangKouList(DangKou user) {
        return this.baseMapper.selectDangKouList(user);
    }

    @Override
    public boolean haveAddress(DangKou user) {
        LambdaQueryWrapper<DangKou> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DangKou::getAddress, user.getAddress());
        return this.baseMapper.selectList(wrapper).size()>0;
    }

    @Override
    public int deleteDangkouByIds(Long[] userIds) {
        for (Long id : userIds) {
            DangKou dangkou = new DangKou();
            dangkou.setId(id);
            dangkou.setDelFlag("2");
            this.baseMapper.updateById(dangkou);
        }
        return 1;
    }

    @Override
    public List<DangKou> selectByAdmin(DangKou user) {
        LambdaQueryWrapper<DangKou> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DangKou::getAdminId, user.getAdminId());
        wrapper.eq(DangKou::getDelFlag, DelFlag.NOMAL.getCode());
        return this.baseMapper.selectList(wrapper);
    }

    @Override
    public List<DangKou> selectByAdmin(Long adminId) {
        LambdaQueryWrapper<DangKou> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DangKou::getAdminId, adminId);
        wrapper.eq(DangKou::getDelFlag, DelFlag.NOMAL.getCode());
        return this.baseMapper.selectList(wrapper);
    }

    @Override
    public List<DangKou> selectAll() {
        LambdaQueryWrapper<DangKou> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DangKou::getDelFlag, DelFlag.NOMAL.getCode());
        return this.baseMapper.selectList(wrapper);
    }
}
